package com.lzw.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//定义拦截器2
public class MyInterceptor2 implements HandlerInterceptor {

//请求发送到达服务器前的方法
// 有一个返回值，false被拦截，不能执行,true未被拦截，可以执行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("拦截器2拦截到的信息");
        return true;
    }


    //请求在服务器执行完经过的方法
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("拦截器2处理完毕的信息");
    }

    //请求返回到客户端之后要执行的方法

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("拦截器2请求到达客户端后执行的方法");
    }
}
